<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>7.6 Verilog DDS 设计 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../w3cnote/verilog-dds.html" />
<meta name="keywords" content="7.6 Verilog DDS 设计">
<meta name="description" content="DDS 原理 DDS（直接频率合成）技术是根据奈奎斯特抽样定理及数字处理技术，把一系列的模拟信号进行不失真的抽样，将得到的数字信号存储在存储器中，并在时钟的控制下，通过数模转换，将数字量变成模拟信号的方法。 DDS 模块主要由相位累加器、查找表、DAC 转换器和低通滤波器组成，基本结构如下。  相位累加器，是 DDS 的核心组成部分，用于实现相位的累加，并输出相应的幅值。相位累加器由 M 位宽加法器和 M 位宽寄存器组成，通过时钟控制，..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<div class="container navigation">
    <div class="row">
        <div class="col nav">
            

                        <ul class="pc-nav" id="note-nav">
                <li><a href="../">首页</a></li>
                <li><a href="../w3cnote">笔记首页</a></li>
                <li><a href="../w3cnote/android-tutorial-intro.html" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" title="ES6 教程">ES6 教程</a></li>
                <li><a href="../w3cnote/ten-sorting-algorithm.html" title="排序算法">排序算法</a></li>
                <li><a href="../w3cnote/hadoop-tutorial.html" title="Hadoop 教程">Hadoop</a></li>
                <li><a href="../w3cnote/zookeeper-tutorial.html" title="Zookeeper 教程">Zookeeper</a></li>
                <li><a href="../w3cnote/verilog-tutorial.html" title="Verilog 教程">Verilog</a></li>
                <li><a href="../w3cnote_genre/code" title="编程技术">编程技术</a></li> 
                <li><a href="../w3cnote_genre/coderlife" title="程序员人生">程序员人生</a></li>
                
                <!--<li><a href="javascript:;" class="runoob-pop">登录</a></li>
                
                
                        <li>
                <a style="font-weight:bold;" href="../linux/linux-tutorial.html#yunserver" target="_blank" onclick="_hmt.push(['_trackEvent', 'aliyun', 'click', 'aliyun'])" title="kkb">云服务器</a>
                </li>
                <li><a href="http://gk.link/a/104mQ" target="_blank" style="font-weight: bold;"onclick="_hmt.push(['_trackEvent', '极客时间', 'click', 'jike'])" title="我的圈子">极客时间</a></li>
            
                
                <li><a target="_blank" href="../shoppinglist" rel="nofollow">知识店铺</a></li> 
        -->
            </ul>
                        
              
            <ul class="mobile-nav">
                <li><a href="../w3cnote">首页</a></li>
                <li><a href="../w3cnote_genre/android" target="_blank" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" target="_blank" title="ES6 教程">ES6</a></li>
                <li><a href="../w3cnote_genre/joke" target="_blank" title="程序员笑话">逗乐</a></li>
                
                <a href="javascript:void(0)" class="search-reveal">Search</a> 
            </ul>
            
        </div>
    </div>
</div>


<!--  内容  -->
<div class="container main">
	<div class="row">

		<!--  Android 基础入门教程 start  -->
	<div class="col left-column" style="display:none;">
		<div class="tab">Verilog 教程</div>
		<div class="sidebar-box gallery-list">
			<div class="design" id="leftcolumn">  
			</div> 
		</div> 
	</div>
	<!--  Android 基础入门教程 end  -->
		<div class="col middle-column big-middle-column">
	 			<div class="article">
			<div class="article-heading">
				<h2>7.6 Verilog DDS 设计</h2>				<h3><em>分类</em> <a href="../w3cnote_genre/verilog" title="Verilog 教程" >Verilog 教程</a> </h3>
			</div>
			<div class="article-body note-body">
				<div class="article-intro">
					<h3>DDS 原理</h3><p>
DDS（直接频率合成）技术是根据奈奎斯特抽样定理及数字处理技术，把一系列的模拟信号进行不失真的抽样，将得到的数字信号存储在存储器中，并在时钟的控制下，通过数模转换，将数字量变成模拟信号的方法。</p><p>
DDS 模块主要由相位累加器、查找表、DAC 转换器和低通滤波器组成，基本结构如下。</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/KogSsjzSTCoDbr9S.png"  /></p>
<p>相位累加器，是 DDS 的核心组成部分，用于实现相位的累加，并输出相应的幅值。相位累加器由 <strong><em>M</em></strong> 位宽加法器和 <strong><em>M</em></strong> 位宽寄存器组成，通过时钟控制，将上一次累加结果反馈到加法器输入端实现累加功能，从而使每个时钟周期内的相位递增数为 <strong><em>K</em></strong>，并取相位累加结果作为地址输出给 ROM 查找表部分。</p>
<p>幅值查找表，存储着每个相位对应的二进制数字幅度。在每个时钟周期内，查找表对相位累加器输出的相位地址信息进行寻址，然后输出对应的二进制幅度数字离散值。假设查找表地址为 <strong><em>M</em></strong> 位，输出数据为 <strong><em>N</em></strong> 位，则查找表的容量大小为 <img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/mHuZv2REp4ZSscYO.png">。不难看出，输出信号的相位分辨率为：</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/u6VUBptgAYsnEfsz.png"></p>
<p>DAC 转换器，将数字信号转换为模拟信号。实际上，DAC 输出的信号并不是连续的，而是根据每位代码的权重，将每一位输入的数字量进行求和，然后以其分辨率为单位进行模拟的输出。实际输出的信号是阶梯状的模拟线型信号，所以要对其进行平滑处理，一般使用滤波器滤波。</p><p>
低通滤波器，由于 DAC 转换器输出的模拟信号存在阶梯状的缺陷，所以要对其进行平滑处理，滤除掉大部分的杂散信号，使输出信号变为比较理想的模拟信号。</p>
<p>
DDS 工作时，频率控制字 <strong><em>K</em></strong> 与 <strong><em>M</em></strong> 比特位的相位累加器相加，得到的结果作为相位值。在每一个时钟周期内以二进制数的形式送给 ROM 查找表，将相位信息转化为数字化的正弦幅度值，再经过数模转换转化为阶梯形状的模拟信号。待信号经过系统滤波滤除大部分的杂散信号后，就可以得到一个比较纯正的正弦波。</p>
<p>从频率分解的角度讲，ROM 查找表将输入频率<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/HFSJHPLQNTYMq9FG.png">分解成了<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/VvqaxosD86lXSV2Y.png" />份，输出频率<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/RfEC3ntul1mqenQj.png"/>占用的份数正是步进频率控制字 <strong><em>K</em></strong>。 所以 DDS 输出频率可以表示为：</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/ixFOiN3Ey7H1EaJh.png" alt="" /></p>
<p>从相位角度讲，在时间<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/EdPLOV7Iu42Q3JlK.png" alt="" />内由频率控制字 <strong><em>K</em></strong> 控制输出的相位增量为：</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/aIwftzwEvHgksl5J.png" alt="" /></p>
<p>考虑此时输出频率的角速度<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/1Xm1rQpV0y9b7IbK.png" alt="" />，时间<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/EdPLOV7Iu42Q3JlK-1.png" alt="" />内输出频率的相位增量还可以表示为：</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/Q1XTz6YsiNB3lwch.png" alt="" /></p><p>
由上述两式也可以推导出 DDS 输出频率与输入频率之间的关系。</p>

<h3>DDS 设计</h3>
<p><strong>设计说明</strong></p><p>
下面只对 DAC 之前的 DDS 电路进行设计。</p><p>
设计的 DDS 特性有：</p>
<ul><li>
1）频率可控；</li><li>
2）起始相位可控；</li><li>
3）幅值可控；</li><li>
4）正弦波、三角波和方波可选择输出；</li><li>
5）资源优化：波形存储文件只采用了四分之一的正弦波数据。</li></ul>
<p><strong>生成 ROM</strong></p><p>
ROM 模块最好使用定制的 ip 核，时序和面积都会有更好的优化。定制的 ROM 还需要指定数据文件，例如 ISE 的 ROM 数据文件后缀为 <span class="marked">.coe</span>，Quartus II 的 ROM 数据文件后缀为 <span class="marked">.mif</span>。</p>
<p>为了方便仿真，这里用代码编写 ROM 模块，地址宽度为 8bit，数据宽度 10bit。</p><p>
为了节省空间，只存四分之一的正弦波形，然后根据对称性进行平移，即可得到一个完整周期正弦波数据波形。</p><p>
为实现 DDS 模式多样化，还加入了三角波、方波的 ROM 程序。</p><p>
实现代码如下（全都包含在文件 mem.v 中）。</p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
<span style="color: #A52A2A; font-weight: bold;">module</span> mem<span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clk<span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//reference clock</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rstn <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//resetn, low effective</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; en <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//start to generating waves</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; sel <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//waves selection</span><br />
<br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; addr <span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dout_en <span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp;dout<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//data out, 10bit width</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//data out fROM ROMs</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">wire</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q_tri <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">wire</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q_square <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">wire</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q_cos <span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//ROM addr</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;en_r <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #5D478B;">@</span><span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">posedge</span> clk <span style="color: #A52A2A; font-weight: bold;">or</span> <span style="color: #A52A2A; font-weight: bold;">negedge</span> rstn<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #5D478B;">!</span>rstn<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; en_r &nbsp; <span style="color: #5D478B;">&lt;=</span> <span style="color: #ff0055;">2'b0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; en_r &nbsp; <span style="color: #5D478B;">&lt;=</span> <span style="color: #9F79EE;">&#123;</span>en_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #5D478B;">,</span> en<span style="color: #9F79EE;">&#125;</span> <span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//delay one cycle for en</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">assign</span> dout &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> en_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">?</span> <span style="color: #9F79EE;">&#40;</span>q_tri <span style="color: #5D478B;">|</span> q_square <span style="color: #5D478B;">|</span> q_cos<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">:</span> <span style="color: #ff0055;">1</span><span style="color: #ff0055;">0'b0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">assign</span> dout_en &nbsp; <span style="color: #5D478B;">=</span> en_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//ROM instiation</span><br />
&nbsp; &nbsp; cos_ROM &nbsp; &nbsp; &nbsp;u_cos_ROM <span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.clk &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>clk<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.en &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>en_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">&amp;</span> <span style="color: #9F79EE;">&#40;</span>sel <span style="color: #5D478B;">==</span> <span style="color: #ff0055;">2'b0</span><span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> &nbsp;<span style="color: #00008B; font-style: italic;">//sel = 0, cos wave</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.addr &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.q &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>q_cos<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; square_ROM &nbsp; u_square_ROM <span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.clk &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>clk<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.en &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>en_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">&amp;</span> sel <span style="color: #5D478B;">==</span> <span style="color: #ff0055;">2'b01</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> &nbsp;<span style="color: #00008B; font-style: italic;">//sel = 1, square wave</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.addr &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.q &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>q_square<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; tri_ROM &nbsp; &nbsp; &nbsp;u_tri_ROM <span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.clk &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>clk<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.en &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>en_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">&amp;</span> sel <span style="color: #5D478B;">==</span> <span style="color: #ff0055;">2'b10</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> <span style="color: #00008B; font-style: italic;">//sel = 2, triangle wave</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.addr &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;.q &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>q_tri<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
<br />
<span style="color: #A52A2A; font-weight: bold;">endmodule</span><br />
<br />
<span style="color: #00008B; font-style: italic;">//square waves ROM</span><br />
<span style="color: #A52A2A; font-weight: bold;">module</span> square_ROM <span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clk<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; en<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; addr<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; q<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//1 in first half cycle, and 0 in second half cycle</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #5D478B;">@</span><span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">posedge</span> clk<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>en<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> <span style="color: #9F79EE;">&#123;</span> <span style="color: #ff0055;">10</span><span style="color: #9F79EE;">&#123;</span><span style="color: #9F79EE;">&#40;</span>addr <span style="color: #5D478B;">&lt;</span> <span style="color: #ff0055;">128</span><span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#125;</span> <span style="color: #9F79EE;">&#125;</span><span style="color: #5D478B;">;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<span style="color: #A52A2A; font-weight: bold;">endmodule</span><br />
<br />
&nbsp;<span style="color: #00008B; font-style: italic;">//triangle waves ROM</span><br />
<span style="color: #A52A2A; font-weight: bold;">module</span> tri_ROM <span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clk<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; en<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; addr<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; q<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//rising edge, addr -&gt; 0x0, 0x3f</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #5D478B;">@</span><span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">posedge</span> clk<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>en<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>addr <span style="color: #5D478B;">&lt;</span> <span style="color: #ff0055;">128</span><span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> <span style="color: #9F79EE;">&#123;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">6</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">3'b0</span><span style="color: #9F79EE;">&#125;</span><span style="color: #5D478B;">;</span> &nbsp; <span style="color: #00008B; font-style: italic;">//rising edge &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span> <span style="color: #00008B; font-style: italic;">//falling edge</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> <span style="color: #ff0055;">1</span><span style="color: #ff0055;">0'h3ff</span> <span style="color: #5D478B;">-</span> <span style="color: #9F79EE;">&#123;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">6</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">3'b0</span><span style="color: #9F79EE;">&#125;</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<span style="color: #A52A2A; font-weight: bold;">endmodule</span><br />
<br />
<span style="color: #00008B; font-style: italic;">//Better use mem ip.</span><br />
<span style="color: #00008B; font-style: italic;">//This format is easy for simulation</span><br />
<span style="color: #A52A2A; font-weight: bold;">module</span> cos_ROM <span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clk<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; en<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; addr<span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; q<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #A52A2A; font-weight: bold;">wire</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">8</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ROM_t <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">0</span> <span style="color: #5D478B;">:</span> <span style="color: #ff0055;">64</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//as the symmetry of cos function, just store 1/4 data of one cycle</span><br />
&nbsp; &nbsp;<span style="color: #A52A2A; font-weight: bold;">assign</span> ROM_t<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">0</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">64</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">=</span> <span style="color: #9F79EE;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">511</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">510</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">510</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">509</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">508</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">507</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">505</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">503</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">501</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">498</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">495</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">492</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">488</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">485</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">481</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">476</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">472</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">467</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">461</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">456</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">450</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">444</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">438</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">431</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">424</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">417</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">410</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">402</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">395</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">386</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">378</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">370</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">361</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">352</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">343</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">333</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">324</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">314</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">304</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">294</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">283</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">273</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">262</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">251</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">240</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">229</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">218</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">207</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">195</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">183</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">172</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">160</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">148</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">136</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">124</span><span style="color: #5D478B;">,</span> <span style="color: #ff0055;">111</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">99</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">87</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">74</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">62</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">50</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">37</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">25</span> <span style="color: #5D478B;">,</span> <span style="color: #ff0055;">12</span> <span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0055;">0</span> <span style="color: #9F79EE;">&#125;</span> <span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #5D478B;">@</span><span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">posedge</span> clk<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>en<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">6</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">==</span> <span style="color: #ff0055;">2'b00</span> <span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span> &nbsp;<span style="color: #00008B; font-style: italic;">//quadrant 1, addr[0, 63]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> ROM_t<span style="color: #9F79EE;">&#91;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">5</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">+</span> <span style="color: #ff0055;">1</span><span style="color: #ff0055;">0'd512</span> <span style="color: #5D478B;">;</span> <span style="color: #00008B; font-style: italic;">//上移</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">6</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">==</span> <span style="color: #ff0055;">2'b01</span> <span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span> <span style="color: #00008B; font-style: italic;">//2nd, addr[64, 127]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> <span style="color: #ff0055;">1</span><span style="color: #ff0055;">0'd512</span> <span style="color: #5D478B;">-</span> ROM_t<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">64</span><span style="color: #5D478B;">-</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">5</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">;</span> <span style="color: #00008B; font-style: italic;">//两次翻转</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">6</span><span style="color: #9F79EE;">&#93;</span> <span style="color: #5D478B;">==</span> <span style="color: #ff0055;">2'b10</span> <span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span> <span style="color: #00008B; font-style: italic;">//3rd, addr[128, 192]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> <span style="color: #ff0055;">1</span><span style="color: #ff0055;">0'd512</span> <span style="color: #5D478B;">-</span> ROM_t<span style="color: #9F79EE;">&#91;</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">5</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#93;</span><span style="color: #5D478B;">;</span> <span style="color: #00008B; font-style: italic;">//翻转右移</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span> &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//4th quadrant, addr [193, 256]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> <span style="color: #ff0055;">1</span><span style="color: #ff0055;">0'd512</span> <span style="color: #5D478B;">+</span> ROM_t<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">64</span><span style="color: #5D478B;">-</span>addr<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">5</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#93;</span><span style="color: #5D478B;">;</span> <span style="color: #00008B; font-style: italic;">//翻转上移</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q <span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<span style="color: #A52A2A; font-weight: bold;">endmodule</span><br />
</div></div>
<p><strong>DDS 控制模块</strong></p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
<span style="color: #A52A2A; font-weight: bold;">module</span> dds<span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clk<span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//reference clock</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rstn <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//resetn, low effective</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wave_en <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//start to generating waves</span><br />
<br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; wave_sel <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//waves selection</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; wave_amp <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//waves amplitude control</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; phase_init<span style="color: #5D478B;">,</span> &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//initial phase</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">input</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; f_word <span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//frequency control word</span><br />
<br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp;dout<span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//data out, 10bit width</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">output</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dout_en<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//phase acculator</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;phase_acc_r <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #5D478B;">@</span><span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">posedge</span> clk <span style="color: #A52A2A; font-weight: bold;">or</span> <span style="color: #A52A2A; font-weight: bold;">negedge</span> rstn<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #5D478B;">!</span>rstn<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phase_acc_r &nbsp; &nbsp;<span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>wave_en<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phase_acc_r &nbsp; &nbsp;<span style="color: #5D478B;">&lt;=</span> phase_acc_r <span style="color: #5D478B;">+</span> f_word <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phase_acc_r &nbsp; &nbsp;<span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//ROM addr</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mem_addr_r <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #5D478B;">@</span><span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">posedge</span> clk <span style="color: #A52A2A; font-weight: bold;">or</span> <span style="color: #A52A2A; font-weight: bold;">negedge</span> rstn<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #5D478B;">!</span>rstn<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mem_addr_r &nbsp; &nbsp; <span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span>wave_en<span style="color: #9F79EE;">&#41;</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mem_addr_r &nbsp; &nbsp; <span style="color: #5D478B;">&lt;=</span> phase_acc_r <span style="color: #5D478B;">+</span> phase_init <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">else</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mem_addr_r &nbsp; &nbsp; <span style="color: #5D478B;">&lt;=</span> 'b0 <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//ROM instiation</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">wire</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; dout_temp <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; mem &nbsp;u_mem_wave<span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .clk &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>clk<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//reference clock</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .rstn &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>rstn<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//resetn, low effective</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .en &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>wave_en<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//start to generating waves</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .sel &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>wave_sel<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//waves selection</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .addr &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>mem_addr_r<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .dout_en <span style="color: #9F79EE;">&#40;</span>dout_en<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .dout &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>dout_temp<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span> &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//data out, 10bit width</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//amplitude</span><br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//0 -&gt; dout/1 &nbsp; //1 -&gt; dout/2 &nbsp; //2 -&gt; dout/4 &nbsp; //3 -&gt; dout/8</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">assign</span> &nbsp; &nbsp; &nbsp; dout <span style="color: #5D478B;">=</span> dout_temp <span style="color: #5D478B;">&gt;&gt;</span> wave_amp <span style="color: #5D478B;">;</span><br />
<span style="color: #A52A2A; font-weight: bold;">endmodule</span><br />
</div></div>
<p><strong>testbench </strong></p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
<span style="color: #008800;">`timescale</span> <span style="color: #ff0055;">1ns</span><span style="color: #5D478B;">/</span><span style="color: #ff0055;">1ns</span><br />
<br />
<span style="color: #A52A2A; font-weight: bold;">module</span> test <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;clk <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rstn <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wave_en <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp;wave_sel <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp;wave_amp <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp;phase_init <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">reg</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; &nbsp;f_word <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">wire</span> <span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span> &nbsp; dout <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">wire</span> &nbsp; &nbsp; &nbsp; &nbsp; dout_en <span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//(1)clk, reset and other constant regs</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">initial</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; clk &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rstn &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span><span style="color: #ff0055;">100</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rstn &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b1</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span><span style="color: #ff0055;">10</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">forever</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span><span style="color: #ff0055;">5</span> <span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp;clk <span style="color: #5D478B;">=</span> <span style="color: #5D478B;">~</span>clk <span style="color: #5D478B;">;</span> &nbsp; <span style="color: #00008B; font-style: italic;">//system clock, 100MHz</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//(2)signal setup ;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">parameter</span> &nbsp; &nbsp;clk_freq &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">100000000</span> <span style="color: #5D478B;">;</span> <span style="color: #00008B; font-style: italic;">//100MHz</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">integer</span> &nbsp; &nbsp; &nbsp;freq_dst &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">2000000</span> <span style="color: #5D478B;">;</span> &nbsp; <span style="color: #00008B; font-style: italic;">//2MHz</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">integer</span> &nbsp; &nbsp; &nbsp;phase_coe &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">2</span><span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//1/4 cycle, that is pi/2</span><br />
<br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">initial</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_en &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//(a)cos wave, pi/2 phase</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_amp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">2'd1</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_sel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">2'd0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; phase_init &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">256</span><span style="color: #5D478B;">/</span>phase_coe <span style="color: #5D478B;">;</span> &nbsp; <span style="color: #00008B; font-style: italic;">//pi/8 initialing-phase</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f_word &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">&lt;&lt;</span><span style="color: #ff0055;">8</span><span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">*</span> freq_dst <span style="color: #5D478B;">/</span> clk_freq<span style="color: #5D478B;">;</span> <span style="color: #00008B; font-style: italic;">//get the frequency control word</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span><span style="color: #ff0055;">500</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">@</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #A52A2A; font-weight: bold;">negedge</span> clk<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_en &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b1</span> <span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00008B; font-style: italic;">//start generating waves</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span> <span style="color: #ff0055;">2000</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//(b)triangle wave, pi/4 initialing-phase</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_en &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b0</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_sel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">2'd2</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; phase_init &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">256</span><span style="color: #5D478B;">/</span><span style="color: #ff0055;">4</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_amp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">2'd2</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span> <span style="color: #ff0055;">50</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; wave_en &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">1'b1</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//(3) module instantiaion</span><br />
&nbsp; &nbsp; dds u_dds<span style="color: #9F79EE;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .clk &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>clk<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .rstn &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>rstn<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .wave_en &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>wave_en<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .wave_sel &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>wave_sel<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .wave_amp &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>wave_amp<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">1</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .phase_init &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>phase_init<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .f_word &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>f_word<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">7</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .dout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #9F79EE;">&#40;</span>dout<span style="color: #9F79EE;">&#91;</span><span style="color: #ff0055;">9</span><span style="color: #5D478B;">:</span><span style="color: #ff0055;">0</span><span style="color: #9F79EE;">&#93;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .dout_en &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #9F79EE;">&#40;</span>dout_en<span style="color: #9F79EE;">&#41;</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00008B; font-style: italic;">//(4) finish the simulation</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">always</span> <span style="color: #A52A2A; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">#</span><span style="color: #ff0055;">100</span><span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">if</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #9932CC;">$time</span> <span style="color: #5D478B;">&gt;=</span> <span style="color: #ff0055;">100000</span><span style="color: #9F79EE;">&#41;</span> <span style="color: #9932CC;">$finish</span> <span style="color: #5D478B;">;</span><br />
&nbsp; &nbsp; <span style="color: #A52A2A; font-weight: bold;">end</span><br />
<span style="color: #A52A2A; font-weight: bold;">endmodule</span> <br />
</div></div>
<p><strong>仿真结果</strong></p><p>
如下图所示，将输出信号调整为模拟显示。</p>
<ul><li>
1）可见正弦波频率为 2MHz，与频率控制字对应；</li><li>
2）正弦波初始相位为 1/2 周期，三角波初始相位为 1/4 周期，符合设置；</li><li>
3）三角波赋值为正弦波的一半，幅值也可控制；</li><li>
4）输出波形为正弦波和三角波，可以正常切换</li><li>
5）正弦波波形没有异常，只用 1/4 周期的正弦波数据就完成了完整正弦波的输出。</li></ul>
<p>限于篇幅，仿真只测试了部分特性。读者可以修改参数测试下其他特性，例如其他频率，方波的输出等。</p>
<p><a target="_blank" href="../wp-content/uploads/2020/10/fIaEwhJrGKDtgEQp.png" rel="noopener noreferrer"><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2020/10/fIaEwhJrGKDtgEQp.png"  /></a></p>

<h3>附录：matlab使用</h3>
<p><strong>1/4 周期正弦波数据生成</strong></p><p>
使用 matlab 生成 1/4 周期正弦波数据描述如下，并对拼接完整正弦波的过程做了仿真。</p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
clear all<span style="color: #5D478B;">;</span>close all<span style="color: #5D478B;">;</span>clc<span style="color: #5D478B;">;</span><br />
<span style="color: #5D478B;">%=======================================================</span><br />
<span style="color: #5D478B;">%</span> generating <span style="color: #ff0055;">1</span><span style="color: #5D478B;">/</span><span style="color: #ff0055;">4</span> cos wave data <span style="color: #A52A2A; font-weight: bold;">with</span> txt hex format<br />
<span style="color: #5D478B;">%=======================================================</span><br />
<br />
N &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">64</span> <span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5D478B;">%</span>共<span style="color: #ff0055;">256</span>个数据，取<span style="color: #ff0055;">1</span><span style="color: #5D478B;">/</span><span style="color: #ff0055;">4</span><br />
n &nbsp; <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">0</span><span style="color: #5D478B;">:</span>N <span style="color: #5D478B;">;</span><br />
w &nbsp; <span style="color: #5D478B;">=</span> n<span style="color: #5D478B;">/</span>N <span style="color: #5D478B;">*</span>pi<span style="color: #5D478B;">/</span><span style="color: #ff0055;">2</span> <span style="color: #5D478B;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5D478B;">%</span>量化到pi<span style="color: #5D478B;">/</span><span style="color: #ff0055;">2</span>内<br />
st &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #9F79EE;">&#40;</span><span style="color: #ff0055;">2</span><span style="color: #5D478B;">^</span><span style="color: #ff0055;">10</span> <span style="color: #5D478B;">/</span><span style="color: #ff0055;">2</span> <span style="color: #5D478B;">-</span><span style="color: #ff0055;">1</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">*</span>cos<span style="color: #9F79EE;">&#40;</span>w<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span> &nbsp; <span style="color: #5D478B;">%</span>正弦波数据取10bit<br />
st &nbsp;<span style="color: #5D478B;">=</span> floor<span style="color: #9F79EE;">&#40;</span>st<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span><br />
<br />
<span style="color: #5D478B;">%%</span> 第一象限拼接<br />
st1 &nbsp;<span style="color: #5D478B;">=</span> st<span style="color: #5D478B;">+</span><span style="color: #ff0055;">512</span> <span style="color: #5D478B;">;</span><br />
figure<span style="color: #9F79EE;">&#40;</span><span style="color: #ff0055;">5</span><span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span>plot<span style="color: #9F79EE;">&#40;</span>n<span style="color: #5D478B;">,</span> st1<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span><br />
hold on <span style="color: #5D478B;">;</span><br />
<br />
<span style="color: #5D478B;">%%</span> 第二象限拼接<br />
n2 &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">64</span> <span style="color: #5D478B;">+</span> n <span style="color: #5D478B;">;</span><br />
st2 <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">512</span> <span style="color: #5D478B;">-</span> st<span style="color: #9F79EE;">&#40;</span><span style="color: #ff0055;">64</span><span style="color: #5D478B;">-</span>n<span style="color: #5D478B;">+</span><span style="color: #ff0055;">1</span><span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
plot<span style="color: #9F79EE;">&#40;</span>n2<span style="color: #5D478B;">,</span> st2<span style="color: #9F79EE;">&#41;</span><span style="color: #5D478B;">;</span><br />
hold on<br />
<br />
<span style="color: #5D478B;">%%</span> 第三象限拼接<br />
n3 &nbsp;<span style="color: #5D478B;">=</span> <span style="color: #ff0055;">128</span> <span style="color: #5D478B;">+</span> n <span style="color: #5D478B;">;</span><br />
st3 <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">512</span> <span style="color: #5D478B;">-</span> st <span style="color: #5D478B;">;</span><br />
plot<span style="color: #9F79EE;">&#40;</span>n3<span style="color: #5D478B;">,</span> st3<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span><br />
hold on <span style="color: #5D478B;">;</span><br />
<br />
<span style="color: #5D478B;">%%</span> 第四象限拼接<br />
n4 <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">192</span> <span style="color: #5D478B;">+</span> n <span style="color: #5D478B;">;</span><br />
st4 <span style="color: #5D478B;">=</span> <span style="color: #ff0055;">512</span> <span style="color: #5D478B;">+</span> st<span style="color: #9F79EE;">&#40;</span><span style="color: #ff0055;">64</span><span style="color: #5D478B;">-</span>n<span style="color: #5D478B;">+</span><span style="color: #ff0055;">1</span><span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span><br />
plot<span style="color: #9F79EE;">&#40;</span>n4<span style="color: #5D478B;">,</span> st4<span style="color: #9F79EE;">&#41;</span> <span style="color: #5D478B;">;</span><br />
hold on <span style="color: #5D478B;">;</span><br />
</div></div>
<h3>源码下载</h3>
<p><a href="../wp-content/uploads/2020/10/7.6dds.zip" download class="download">Download</a></p>
				</div>
			</div>
			<div class="previous-next-links">
			<div class="previous-design-link">← <a href="../w3cnote/verilog-numerical-conversion.html" rel="prev"> 8.1 Verilog 数值转换</a> </div>
			<div class="next-design-link"></div>
			</div>
						<div class="article-heading-ad" id="w3cnote-ad728">
			<script async src=""></script>
			<!-- 移动版 自动调整 -->
			<ins class="adsbygoogle"
			     style="display:inline-block;min-width:300px;max-width:970px;width:100%;height:90px"
			     data-ad-client="ca-pub-5751451760833794"
			     data-ad-slot="1691338467"
			     data-ad-format="horizontal"></ins>
			<script>
			(adsbygoogle = window.adsbygoogle || []).push({});
			</script>
			</div>
			<style>
@media screen and (max-width: 768px) {
	#w3cnote-ad728 {
		display: none;
	}
}
p.note-author {
    border-bottom: 1px solid #ddd;
    font-size: 18px;
    font-weight: bold;
    color: #78a15a;
    padding-bottom: 2px;
    margin-bottom: 4px;
}
</style>
<script>
var aid = 23309;
</script>
	</div>
		
	</div>
	<div class="listcol last right-column">

	<script type="text/javascript">
jQuery(document).ready(function ($){
	var total = $(".membership li").length;
	var left_list = '';
	href = window.location.href;
	
	$(".membership li").each(function(index, value){

		left_list += $(this).html();

		cur_href = $(this).find("a").attr("href");
		cur_obj = $(this);
		
		if(href.match(cur_href) != null) {
			if(index==0) {
				$(".previous-design-link").hide();
			}
			if(index==(total-1)) {
				$(".next-design-link").hide();
			}
			prev_href = cur_obj.prev("li").find("a").attr("href");
			prev_title = cur_obj.prev("li").find("a").attr("title");

			next_href = cur_obj.next("li").find("a").attr("href");
			next_title = cur_obj.next("li").find("a").attr("title");
			if(prev_title) {
				$(".previous-design-link a").attr("href", prev_href);
				$(".previous-design-link a").attr("title", prev_title);
				$(".previous-design-link a").text(prev_title);
			} else {
				$(".previous-design-link").html("");
			}

			if(next_title) {
				$(".next-design-link a").attr("href", next_href);
				$(".next-design-link a").attr("title", next_title);
				$(".next-design-link a").text(next_title);
			} else {
				$(".next-design-link").html("");
			}
		}
	});

	$("#leftcolumn").html(left_list);
});
	</script>
	<div class="sidebar-box cate-list">
	<div class="sidebar-box recommend-here list-link">
	<a href="javascript:void(0);">Verilog 教程</a>	</div>
	
	<ul class="membership">
		
	<li><a target="_top" data-id="22850" title="1.1 Verilog 教程" href="../w3cnote/verilog-tutorial.html" >1.1 Verilog 教程</a></li>
	
		
	<li><a target="_top" data-id="22851" title="1.2 Verilog 简介" href="../w3cnote/verilog-intro.html" >1.2 Verilog 简介</a></li>
	
		
	<li><a target="_top" data-id="22852" title="1.3 Verilog 环境搭建" href="../w3cnote/verilog-install.html" >1.3 Verilog 环境搭建</a></li>
	
		
	<li><a target="_top" data-id="22866" title="1.4 Verilog 设计方法" href="../w3cnote/verilog-design-method.html" >1.4 Verilog 设计方法</a></li>
	
		
	<li><a target="_top" data-id="22869" title="2.1 Verilog 基础语法" href="../w3cnote/verilog-basic-syntax.html" >2.1 Verilog 基础语法</a></li>
	
		
	<li><a target="_top" data-id="22870" title="2.2 Verilog 数值表示" href="../w3cnote/verilog-number.html" >2.2 Verilog 数值表示</a></li>
	
		
	<li><a target="_top" data-id="22871" title="2.3 Verilog 数据类型" href="../w3cnote/verilog-data-type.html" >2.3 Verilog 数据类型</a></li>
	
		
	<li><a target="_top" data-id="22872" title="2.4 Verilog 表达式" href="../w3cnote/verilog-expression.html" >2.4 Verilog 表达式</a></li>
	
		
	<li><a target="_top" data-id="22935" title="2.5 Verilog 编译指令" href="../w3cnote/verilog-compile-instruction.html" >2.5 Verilog 编译指令</a></li>
	
		
	<li><a target="_top" data-id="22931" title="3.1 Verilog 连续赋值" href="../w3cnote/verilog-assign.html" >3.1 Verilog 连续赋值</a></li>
	
		
	<li><a target="_top" data-id="22933" title="3.2 Verilog 时延" href="../w3cnote/verilog-time-delay.html" >3.2 Verilog 时延</a></li>
	
		
	<li><a target="_top" data-id="22936" title="4.1 Verilog 过程结构" href="../w3cnote/verilog-process-structure.html" >4.1 Verilog 过程结构</a></li>
	
		
	<li><a target="_top" data-id="22939" title="4.2 Verilog 过程赋值" href="../w3cnote/verilog-process-assign.html" >4.2 Verilog 过程赋值</a></li>
	
		
	<li><a target="_top" data-id="22941" title="4.3 Verilog 时序控制" href="../w3cnote/verilog-timing-control.html" >4.3 Verilog 时序控制</a></li>
	
		
	<li><a target="_top" data-id="22943" title="4.4 Verilog 语句块" href="../w3cnote/verilog-statements-block.html" >4.4 Verilog 语句块</a></li>
	
		
	<li><a target="_top" data-id="22948" title="4.5 Verilog 条件语句" href="../w3cnote/verilog-condition-statement.html" >4.5 Verilog 条件语句</a></li>
	
		
	<li><a target="_top" data-id="22950" title="4.6 Verilog 多路分支语句" href="../w3cnote/verilog-case.html" >4.6 Verilog 多路分支语句</a></li>
	
		
	<li><a target="_top" data-id="22951" title="4.7 Verilog 循环语句" href="../w3cnote/verilog-loop.html" >4.7 Verilog 循环语句</a></li>
	
		
	<li><a target="_top" data-id="22954" title="4.8 Verilog 过程连续赋值" href="../w3cnote/verilog-deassign.html" >4.8 Verilog 过程连续赋值</a></li>
	
		
	<li><a target="_top" data-id="22966" title="5.1 Verilog 模块与端口" href="../w3cnote/verilog-module-port.html" >5.1 Verilog 模块与端口</a></li>
	
		
	<li><a target="_top" data-id="22969" title="5.2 Verilog 模块例化" href="../w3cnote/verilog-generate.html" >5.2 Verilog 模块例化</a></li>
	
		
	<li><a target="_top" data-id="22972" title="5.3 Verilog 带参数例化" href="../w3cnote/verilog-defparam.html" >5.3 Verilog 带参数例化</a></li>
	
		
	<li><a target="_top" data-id="22975" title="6.1 Verilog 函数" href="../w3cnote/verilog-function.html" >6.1 Verilog 函数</a></li>
	
		
	<li><a target="_top" data-id="22982" title="6.2 Verilog 任务" href="../w3cnote/verilog-task.html" >6.2 Verilog 任务</a></li>
	
		
	<li><a target="_top" data-id="22990" title="6.3 Verilog 状态机" href="../w3cnote/verilog-fsm.html" >6.3 Verilog 状态机</a></li>
	
		
	<li><a target="_top" data-id="22999" title="6.4 Verilog 竞争与冒险" href="../w3cnote/verilog-competition-hazard.html" >6.4 Verilog 竞争与冒险</a></li>
	
		
	<li><a target="_top" data-id="23008" title="6.5 Verilog 避免 Latch" href="../w3cnote/verilog-latch.html" >6.5 Verilog 避免 Latch</a></li>
	
		
	<li><a target="_top" data-id="23011" title="6.6 Verilog 仿真激励" href="../w3cnote/verilog-testbench.html" >6.6 Verilog 仿真激励</a></li>
	
		
	<li><a target="_top" data-id="23015" title="6.7 Verilog 流水线" href="../w3cnote/verilog-pipeline-design.html" >6.7 Verilog 流水线</a></li>
	
		
	<li><a target="_top" data-id="23021" title="7.1 Verilog 除法器设计" href="../w3cnote/verilog-dividend.html" >7.1 Verilog 除法器设计</a></li>
	
		
	<li><a target="_top" data-id="23222" title="7.2 Verilog 并行 FIR 滤波器设计" href="../w3cnote/verilog-fir.html" >7.2 Verilog 并行 FIR 滤波器设计</a></li>
	
		
	<li><a target="_top" data-id="23230" title="7.3 Verilog 串行 FIR 滤波器设计" href="../w3cnote/verilog-serial-fir.html" >7.3 Verilog 串行 FIR 滤波器设计</a></li>
	
		
	<li><a target="_top" data-id="23236" title="7.4 Verilog CIC 滤波器设计" href="../w3cnote/verilog-cic.html" >7.4 Verilog CIC 滤波器设计</a></li>
	
		
	<li><a target="_top" data-id="23260" title="7.5 Verilog FFT 设计" href="../w3cnote/verilog-fft.html" >7.5 Verilog FFT 设计</a></li>
	
		<li>
	7.6 Verilog DDS 设计	</li>
	
		
	<li><a target="_top" data-id="23281" title="8.1 Verilog 数值转换" href="../w3cnote/verilog-numerical-conversion.html" >8.1 Verilog 数值转换</a></li>
	
	<li><a target="_top" title="Verilog 教程高级篇" href="../w3cnote/verilog2-tutorial.html" >Verilog 教程高级篇</a></li></ul></div>	</div>
</div>


<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>